package com.dahua.ui.main;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dahua.R;

/**
 * Created by luxs on 2016/5/5.
 */
public class UpdateDialog extends DialogFragment implements View.OnClickListener {

    private TextView title;
    private TextView conntent;
    private TextView negative;
    private TextView positive;
    private View negative_view;

    private static setOnHintListener mlistner;
    private static UpdateDialog dialog;

    private static String mTitle;
    private static String mContent;
    private static String mNegative;
    private static String mPositive;
    private static Boolean mustUpdate  =false;

    public static UpdateDialog newInstance(Boolean mustUpdateBoolean, String title, String content, String negative, String positive, setOnHintListener listner) {
        if (dialog == null) {
            dialog = new UpdateDialog();
        }
        mlistner = listner;
        mTitle = title;
        mContent=content;
        mNegative=negative;
        mPositive=positive;
        mustUpdate = mustUpdateBoolean;
        return dialog;
    }


    public UpdateDialog() {
        setStyle(DialogFragment.STYLE_NO_TITLE, R.style.MyTryUseDialogFragmentForUpdate);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_hint, container);
        title = (TextView) view.findViewById(R.id.title);
        conntent = (TextView) view.findViewById(R.id.conntent);
        negative = (TextView) view.findViewById(R.id.negative);
        positive = (TextView) view.findViewById(R.id.positive);
        negative_view = view.findViewById(R.id.negative_view);

        title.setText(mTitle);
        conntent.setText(mContent);
        negative.setText(mNegative);
        positive.setText(mPositive);
        negative.setOnClickListener(this);
        positive.setOnClickListener(this);

        if (mustUpdate){
            negative.setVisibility(View.GONE);
            negative_view.setVisibility(View.GONE);

        }else {
            negative.setVisibility(View.VISIBLE);
            negative_view.setVisibility(View.VISIBLE);
        }

        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.negative:
                mlistner.onNegative();
                this.dismiss();
                break;
            case R.id.positive:
                mlistner.onPositive();
                this.dismiss();
                break;
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
    public interface setOnHintListener {
        void onNegative();
        void onPositive();
    }
}
